
export function timeFormat(val: string | Date, type: number = 1) {
  const now = new Date(val);
  const year: number | string = now.getFullYear();
  let month: number | string = now.getMonth() + 1;
  let date: number | string = now.getDate();
  let hour: number | string = now.getHours();
  let minute: number | string = now.getMinutes();
  let second: number | string = now.getSeconds();
  let milliseconds: number | string = now.getMilliseconds();
  // 补0显示判定

  month = month > 9 ? month : `0${month}`;
  date = date > 9 ? date : `0${date}`;
  hour = hour > 9 ? hour : `0${hour}`;
  minute = minute > 9 ? minute : `0${minute}`;
  second = second > 9 ? second : `0${second}`;
  milliseconds = milliseconds > 9 ? milliseconds : `0${milliseconds}`;
  // 显示格式类型
  const result1: string = `${year}-${month}-${date} ${hour}:${minute}:${second}`;
  const result2: string = `${year}-${month}-${date}`;
  const result3: string = `${month}-${date}  ${hour}:${minute}`;
  const result4: string = `${month}月${date}日  ${hour}:${minute}`;
  const result5: string = `${year}-${month}-${date} ${hour}:${minute}`;
  const result6: string = `${hour}:${minute}`;

  const result7 = second;
  const result8: string = `${minute}:${second}`;
  const result9: string = `${hour}:${minute}:${second}`;
  const result10 = `${year}-${month}-${date} ${hour}:${minute}:${second}:${milliseconds}`;
  const result11 = `${year}${month}${date}${hour}${minute}${second}${milliseconds}`;
  const result12 = `${month}月${date}日`;
  switch (type) {
    case 1:
      return result1;
    case 2:
      return result2;
    case 3:
      return result3;
    case 4:
      return result4;
    case 5:
      return result5;
    case 6:
      return result6;
    case 8:
      return result8;
    case 9:
      return result9;
    case 10:
      return result10;
    case 11:
      return result11;
    case 12:
      return result12;
    default:
      return result7;
  }
}
